<template>
  <div class="heder-container">
    <div class="icon">
      <i
        class="iconfont icon-top"
        :class="{
          'is-active': isTop
        }"
        @click="setTop"
      ></i>
    </div>
    <div class="icon">
      <i class="iconfont icon-shrink" @click="setMinimize"></i>
    </div>
    <div class="icon">
      <i v-if="!isFullScreen" class="iconfont icon-full-screen" @click="setMaximize"></i>
      <i v-else class="iconfont icon-zoom-out" @click="setUnmaximize"></i>
    </div>
    <div class="icon">
      <i class="iconfont icon-close" @click="close"></i>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const props = defineProps({
  closeType: {
    type: Number,
    default: 0
  }
})

const isTop = ref(false)
const setTop = () => {
  isTop.value = !isTop.value
  window.ipcRenderer.send('setWinTop', isTop.value)
}
const setMinimize = () => {
  window.ipcRenderer.send('minimize')
}
const isFullScreen = ref(false)
const setMaximize = () => {
  isFullScreen.value = true
  window.ipcRenderer.send('maximize')
}
const setUnmaximize = () => {
  isFullScreen.value = false
  window.ipcRenderer.send('unmaximize')
}
const close = () => {
  window.ipcRenderer.send('closeWin', props.closeType)
}
</script>

<style lang="scss" scoped>
.heder-container {
  width: 100%;
  height: 20px;
  background-color: transparent;
  -webkit-app-region: drag;
  position: absolute;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: flex-end;

  .icon {
    height: 100%;
    width: 26px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .icon:hover {
    background-color: #dfdfdf;
  }

  .iconfont {
    font-size: 0.8em;
    -webkit-app-region: no-drag;
  }

  .is-active {
    color: #07c160;
  }
}
</style>
